package org.scmpatrol.scm.diff;

import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.OneToOne;

/**
 * A removal element is the combination of :
 * <UL>
 * <LI>A suppression from the original content
 * <LI>A addition into the original content
 * </UL> *
 * 
 * @author vincent.sellier
 * 
 */
@Entity
@DiscriminatorValue("R")
public class ReplacementDiffElement extends DiffElement {

	@OneToOne(cascade = CascadeType.ALL)
	private RemovalDiffElement removalElement;
	@OneToOne(cascade = CascadeType.ALL)
	private AdditionDiffElement additionElement;

	public ReplacementDiffElement(RemovalDiffElement removal,
			AdditionDiffElement addition) {
		super(DiffElementType.REPLACEMENT, removal.getStartPosition(), addition
				.getContent());
		this.removalElement = removal;
		this.additionElement = addition;
	}

	@Override
	public Integer getLength() {
		return additionElement.getLength();
	}

	public String getRemovedContent() {
		return removalElement.getContent();
	}

	public Integer getRemovedLength() {
		return removalElement.getLength();
	}

}
